package com.xayy.mgt.controller;

import cn.kawins.base.result.ResultBody;
import cn.kawins.mybatis.base.BaseController;
import cn.kawins.spring.mvc.validator.Group;
import com.github.pagehelper.PageInfo;
import com.xayy.mgt.model.NodeTreeInfo;
import com.xayy.mgt.model.dto.NodeInfoDto;
import com.xayy.mgt.model.vo.NodeTreeCopyInfoVo;
import com.xayy.mgt.model.vo.NodeTreeInfoVo;
import com.xayy.mgt.service.NodeInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Nie
 * @version V1.0
 * @date 2023/8/14 14:05
 */
@RestController
@RequestMapping(value = "/nodeTree1")
@Api(tags = "节点树")
public class NodeInfoController extends BaseController<NodeTreeInfo> {

    @Autowired
    private NodeInfoService nodeInfoService;

    @PostMapping("/addOrUpdate")
    @ApiOperation(value = "新增/更新树节点(左侧树)", httpMethod = "POST")
    public ResultBody addOrUpdate(@RequestBody NodeTreeInfo nodeTreeInfo) {

        return nodeInfoService.addOrUpdate(nodeTreeInfo).body();
    }

    @PostMapping("/copyTreeAndNode")
    @ApiOperation(value = "复制节点", httpMethod = "POST")
    public ResultBody copyTreeAndNode(@Validated(Group.Insert.class) @RequestBody NodeTreeCopyInfoVo nodeTreeCopyInfoVo) {
        return nodeInfoService.copyTreeAndNode(nodeTreeCopyInfoVo).body();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除树节点(左侧树)", httpMethod = "DELETE")
    public ResultBody delete(@ApiParam(value = "节点id", required = true) @PathVariable Long id) {
        return nodeInfoService.deleteTreeById(id).body();
    }

    @GetMapping("/getNodeRelation/{nodeId}")
    @ApiOperation(value = "获取节点关联关系", httpMethod = "GET")
    public ResultBody getNodeRelation(@PathVariable Long nodeId) {
        return nodeInfoService.getNodeRelation(nodeId).body();
    }

    @GetMapping("/getChildrenNodeTree/{nodeId}")
    @ApiOperation(value = "获取子节点树", httpMethod = "GET")
    public ResultBody getNodeTree(@PathVariable Long nodeId) {
        return nodeInfoService.getNodeTree(nodeId).body();
    }

    @GetMapping("/getNodeBaseInfo/{nodeId}")
    @ApiOperation(value = "获取单节点基本信息和参数列表", httpMethod = "GET", response = NodeTreeInfoVo.class)
    public ResultBody getNodeBaseInfo(@PathVariable("nodeId") Long nodeId) {
        return nodeInfoService.getNodeBaseInfo(nodeId).body();
    }

    @GetMapping("/info/{nodeId}")
    @ApiOperation(value = "点击节点显示的信息", httpMethod = "GET", response = Map.class)
    public ResultBody getInfo(@PathVariable("nodeId") Long nodeId) {
        return nodeInfoService.getInfo(nodeId).body();
    }

    @DeleteMapping("/deleteNodeInfo/{nodeId}")
    @ApiOperation(value = "删除卫星下的所有节点数据（包括表单）", httpMethod = "DELETE")
    public ResultBody deleteNodeInfo(@PathVariable("nodeId") Long nodeId) {
        return nodeInfoService.deleteNodeInfo(nodeId).body();
    }

    @PostMapping("/pageList")
    @ApiOperation(value = "获取节点配置信息(分页)", httpMethod = "POST", notes = "评估构建体系-根据左侧树id获取右侧数据")
    public ResultBody pageList(@RequestBody NodeInfoDto nodeInfoDto) {
        PageInfo<NodeTreeInfo> page = nodeInfoService.pageList(nodeInfoDto);
        return ResultBody.success(page);
    }

    @GetMapping("/getNodeCodeArray")
    @ApiOperation(value = "获取卫星节点编码数组", httpMethod = "GET", notes = "评估构建体系-根据节点id获取卫星节点编码数组")
    public ResultBody getNodeCodeArray(@RequestParam String nodeId) {
        List<List<String>> array =  nodeInfoService.getNodeCodeArray(nodeId);
        return ResultBody.success(array);
    }

    @GetMapping("/getAllSatelliteList")
    @ApiOperation(value = "获取所有卫星列表", httpMethod = "GET", notes = "评估构建体系-获取所有卫星列表")
    public ResultBody getAllSatelliteList() {
        List<NodeTreeInfo> array =  nodeInfoService.getAllSatelliteList();
        return ResultBody.success(array);
    }


}
